#include <hardware.h>

#define DAC3V_W 0xC2
//#define DAC3V_MSB 0x00 // 0.1V (mode=186)
#define DAC3V_MSB 0x09 // 3.7V (-0.6V) (mode=168)
//#define DAC3V_MSB 0x0F // 5.0V (-0.6V) (mode=156)
#define DAC3V_LSB 0xFF

extern volatile unsigned char full_messages;

void lithium_recharge(unsigned char mode)
{
unsigned char twi_lithium_recharge_msg[] = {DAC3V_W, DAC3V_MSB, DAC3V_LSB};
unsigned char twi_lithium_recharge_msg_length = 3;

if (mode > 186)
    {
    mode = 186;
    }

if (mode < 156)
    {
    mode = 156;
    }

twi_lithium_recharge_msg[1] = 93 - (mode>>1);
twi_lithium_recharge_msg[2] = 255 - ((mode&0x01)<<7);

if (full_messages == 1)
    {
    strf2buffer("Set Lithium Recharge Voltage\r");
    }

send_twi_msg(twi_lithium_recharge_msg, twi_lithium_recharge_msg_length);
}